<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertDefinition name="layout">
	<tiles:putAttribute name="head">
		<style type="text/css">
.block {
	display: block;
}

.pan-log {
	display: none;
}

.singleLine {
	white-space: nowrap;
	width: 10em;
	overflow: hidden;
	text-overflow: ellipsis;
	display: inline-block;
}

#searchPanel {
	display: none;
}
</style>
		<script type="text/javascript">
			var id;

			function selectConsultor(user) {
				helper.confirm("确认", "确定要变更该学员的咨询师为" + user.name + "?", function() {
					//var id = $(source).attr("id");
					var url = "../front/doAppointConsultor";
					$.post(url, {
						studentId : id,
						consultId : user.id
					}, function(data) {
						helper.showMsg(data, {
							successHandler : function() {
								location.reload();
							}
						});
					});
				});
			}

			function selectTutor(user) {
				helper.confirm("确认", "确定要变更该学员的指导员为" + user.name + "?", function() {
					//var id = $(source).attr("id");
					var url = "../front/doAppointTutor";
					$.post(url, {
						studentId : id,
						tutorId : user.id
					}, function(data) {
						helper.showMsg(data, {
							successHandler : function() {
								location.reload();
							}
						});
					});
				});
			}

			$(function() {
				$(".frame").frameDialog({
					width : 500,
					height : 500,
					close : function() {
						location.reload();
					}
				}, function(source) {
					id = $(source).attr("id");
				});

				$(".dailog").frameDialog({
					close : function() {
						if (art.dialog.data("success")) {
							location.reload();
						}
					}
				});

				$(".confirm").confirmDialog(function(data) {
					helper.showMsg(data, {
						okHandler : function() {
							location.reload();
						}
					});
				});

				$(".ajax").anchorAjax(function(a, data) {
					if (data.success) {
						$(a).find("i").toggleClass("icon-star-empty");
						$(a).find("i").toggleClass("icon-star");
					}
				});

				$(".date").datepicker({
					dateFormat : "yy-mm-dd"
				});

				$(".orderLesson").toggle(function() {
					var coursetTr = $(this).closest("tr");

					var signCourseId = $(this).attr("signCourse");
					var url = "../log/listOrderLessonLog";
					$.post(url, {
						signCourseId : signCourseId
					}, function(data) {
						var headerTds = coursetTr.find(".header");
						var tr = coursetTr;
						while (headerTds.length == 0) {
							tr = tr.prev("tr");
							headerTds = tr.find(".header");
						}

						var rowspane = headerTds.attr("rowspan");
						headerTds.attr("rowspan", parseInt(rowspane) + 1);

						var logEle = $(data);

						logEle.find(".dialog").frameDialog({
							width : 500,
							height : 500
						});
						coursetTr.after(logEle);
					});

				}, function() {
					var coursetTr = $(this).closest("tr");
					var headerTds = coursetTr.find(".header");
					var tr = coursetTr;
					while (headerTds.length == 0) {
						tr = tr.prev("tr");
						headerTds = tr.find(".header");
					}

					coursetTr.next("tr").remove();

					var rowspane = headerTds.attr("rowspan");
					headerTds.attr("rowspan", parseInt(rowspane) - 1);
				});

				// 查看日志详情
				$(".btn-log").toggle(function() {
					$(this).closest(".row-fluid").next(".pan-log:first").fadeIn();
				}, function() {
					$(this).closest(".row-fluid").next(".pan-log:first").fadeOut();
				});

				// 
				$(".btn-addSet").click(function() {
					var url = "setSetStudent.jsp";
					art.dialog.open(url, {
						"title" : "报名新课程",
						width : "50%",
						height : "50%",
						close : function() {
							return true;
						}
					});
				});

				$(".btn-modifyStudent").click(function() {
					var url = "modifyStudent.jsp";
					art.dialog.open(url, {
						"title" : "修改学员基础资料",
						width : "50%",
						height : "50%",
						close : function() {
							return true;
						}
					});
				});

				$(".btn-setLessonStudent").click(function() {
					var url = "setLessonStudent.jsp";
					art.dialog.open(url, {
						"title" : "选课",
						width : "50%",
						height : "50%",
						close : function() {
							return true;
						}
					});
				});

				$("#onlyVoid").change(function() {
					if ($(this).prop("checked")) {
						$("#panLearnStatus input").attr("disabled", "disabled").prop("checked", false);
					} else {
						$("#panLearnStatus input").removeAttr("disabled");
					}
				});

				$("#searchBtn").click(function() {
					$("#searchPanel").slideToggle("fast");
				});
			});
		</script>
	</tiles:putAttribute>
	<tiles:putAttribute name="mainBody">
		<form class="form-horizontal">
			<fieldset>
				<legend>我的学员</legend>
				<div class="control-group">
					<label class="control-label">姓名</label>
					<div class="controls">
						<div class="form-inline">
							<input type="text" name="name" value="${param.name}" />
							<label class="checkbox">
								<input type="checkbox" name="onlyVoid" value="true" id="onlyVoid" <s:if test='"true" in #parameters.onlyVoid'>checked="checked"</s:if> />只列出未注册学员
							</label>
							<div style="display: inline; margin-left: 2em" id="panLearnStatus">
								<label class="checkbox">
									<input type="checkbox" name="learnStatus" value="Learning" <s:if test='"Learning" in #parameters.learnStatus'>checked="checked"</s:if> />在读
								</label>
								<label class="checkbox">
									<input type="checkbox" name="learnStatus" value="Freeze" <s:if test='"Freeze" in #parameters.learnStatus'>checked="checked"</s:if> />冻结
								</label>
								<label class="checkbox">
									<input type="checkbox" name="learnStatus" value="Finished" <s:if test='"Finished" in #parameters.learnStatus'>checked="checked"</s:if> />结课
								</label>
							</div>
							<button class="btn btn-primary" type="submit">查询</button>
						</div>
					</div>
				</div>
				<div class="well well-small">
					<a href="#" id="searchBtn">高级查询</a>
					：
					<div class="text-warning">${search}</div>
					<div id="searchPanel">
						<div class="control-group">
							<label class="control-label">是否在咨询跟单</label>
							<div class="controls">
								<div class="form-inline">
									<label class="checkbox">
										<input type="checkbox" name="consultStarred" value="true" <s:if test='"true" in #parameters.consultStarred'>checked="checked"</s:if> />是
									</label>
									<label class="checkbox">
										<input type="checkbox" name="consultStarred" value="false" <s:if test='"false" in #parameters.consultStarred'>checked="checked"</s:if> />否
									</label>
								</div>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">Tutor</label>
							<div class="controls">
								<div class="form-inline">
									<s:iterator value="#tutors" var="tutor">
										<label class="checkbox">
											<input type="checkbox" name="tutor" value="${tutor.id}" <s:if test='id in #parameters.tutor'>checked="checked"</s:if> />${tutor.name}
										</label>
									</s:iterator>
								</div>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label">课程选择</label>
							<div class="controls">
								<div class="form-inline">
									<s:iterator value="#courses" var="course">
										<label class="checkbox">
											<input type="checkbox" name="course" value="${course.id}" <s:if test='id in #parameters.course'>checked="checked"</s:if> />${course.name}
										</label>
									</s:iterator>
								</div>
							</div>
						</div>
						<div class="row-fluid">
							<div class="span6">
								<div class="control-group">
									<label class="control-label">开课时间范围</label>
									<div class="controls">
										<input type="text" class="date input-small" name="startDate" value="${param.startDate}" />~<input type="text" class="date input-small" name="endDate"
											value="${param.endDate}" />
									</div>
								</div>
							</div>
							<div class="span6">
								<div class="control-group">
									<label class="control-label">报名时间范围</label>
									<div class="controls">
										<input type="text" class="date input-small" name="signStartDate" value="${param.signStartDate}" />~<input type="text" class="date input-small" name="signEndDate"
											value="${param.signEndDate}" />
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</fieldset>
		</form>
		<div>每页${students.size}项，共 ${students.totalElements} 项，当前${students.number+1}/ ${students.totalPages}页</div>
		<table class="table">
			<tr>
				<th style="width: 10em">学员信息</th>
				<th>课程</th>
				<th>报名日期</th>
				<th>听课证号</th>
				<th>期限</th>
				<th>开课-结课</th>
				<th>冻结</th>
			</tr>
			<s:iterator value="#students" var="student">
				<s:url namespace="/student" action="modifyStudent" id="modifyStudent">
					<s:param name="id" value="id" />
				</s:url>
				<s:url namespace="/school" action="selectConsultor" id="selectConsultor">
				</s:url>
				<s:url namespace="/school" action="selectTutor" id="selectTutor">
				</s:url>
				<s:url namespace="/signcourse" action="signUp" id="signUp">
					<s:param name="id" value="id" />
				</s:url>
				<s:url namespace="/log" action="viewLogByTime" id="viewLogByTime">
					<s:param name="id" value="id" />
				</s:url>
				<s:url namespace="/consult" action="doUnStarredConsult" id="doUnStarredConsult">
					<s:param name="id" value="id" />
				</s:url>
				<s:url namespace="/consult" action="doStarredConsult" id="doStarredConsult">
					<s:param name="id" value="id" />
				</s:url>
				<s:url namespace="/orderlesson" action="orderAuditionLesson" id="orderAuditionLesson">
					<s:param name="studentId" value="id" />
				</s:url>
				<s:set name="size" value="courses.size" />
				<s:if test="#size == 0">
					<tr>
						<td class="header"><a href="${viewLogByTime}">
								<strong> ${student.name} </strong>
							</a>
							<div>学号:${student.stuId}</div>
							<div>CC:${student.consultor.name}</div>
							<div>Tutor:${student.tutor.name}</div>
							<div>
								<s:if test="consultStarred">
									<a href="${doUnStarredConsult}" title="取消咨询关注该学员" class="ajax">
										<i class="icon-star"></i>
									</a>
								</s:if>
								<s:else>
									<a href="${doStarredConsult}" title="咨询关注该学员" class="ajax">
										<i class="icon-star-empty"></i>
									</a>
								</s:else>
							</div></td>
						<td colspan="6">无注册课程</td>
					</tr>
				</s:if>
				<s:else>
					<s:iterator value="courses" var="signCourse" status="status">
						<s:url namespace="/school" action="createFreezeLog" id="createFreezeLog">
							<s:param name="signId" value="id"></s:param>
							<s:param name="studentid" value="student.id"></s:param>
						</s:url>
						<s:url namespace="/school" action="doResumeCourse" id="resumeCourse">
							<s:param name="signId" value="id"></s:param>
							<s:param name="studentid" value="student.id"></s:param>
						</s:url>
						<s:url namespace="/school" action="doFinishCourse" id="finishCourse">
							<s:param name="signId" value="id"></s:param>
							<s:param name="studentid" value="student.id"></s:param>
						</s:url>
						<tr>
							<s:if test="#status.first">
								<td class="header" rowspan="${size}"><s:if test="consultStarred">
										<a href="${doUnStarredConsult}" title="取消咨询关注该学员" class="ajax">
											<i class="icon-star"></i>
										</a>
									</s:if> <s:else>
										<a href="${doStarredConsult}" title="咨询关注该学员" class="ajax">
											<i class="icon-star-empty"></i>
										</a>
									</s:else> <a href="${viewLogByTime}">
										<strong> ${student.name} </strong>
									</a>
									<div>学号:${student.stuId}</div>
									<div>CC:${student.consultor.name}</div>
									<div>Tutor:${student.tutor.name}</div></td>
							</s:if>
							<s:if test='learnStatus.toString()=="结课"'>
								<s:set name="cssClass" value="'red-bg'"></s:set>
							</s:if>
							<s:elseif test='learnStatus.toString()=="冻结"'>
								<s:set name="cssClass" value="'yellow-bg'"></s:set>
							</s:elseif>
							<s:else>
								<s:set name="cssClass" value="''"></s:set>
							</s:else>
							<td class="${cssClass}"><a href="javascript:void(0)" class="orderLesson" signCourse="${signCourse.id}" title="订课日志">
									<i class="icon-search"></i>查看订课情况
								</a>
								<div class="dropdown">
									<a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown">
										${signCourse.course.name}<span class="caret"></span>
									</a>
									<ul class="dropdown-menu">
										<li><s:url id="orderLesson" action="orderLesson" namespace="/orderlesson">
												<s:param name="signCourseId" value="id"></s:param>
											</s:url> <a href="${orderLesson}">订课</a></li>
										<li><s:url id="orderHistoryLesson" action="orderHistoryLesson" namespace="/orderlesson">
												<s:param name="signCourseId" value="id"></s:param>
											</s:url> <a href="${orderHistoryLesson}">补订历史课程</a></li>

										<li><s:url id="extendSignCourse" action="extendSignCourse" namespace="/signcourse">
												<s:param name="signCourseId" value="id"></s:param>
											</s:url> <a href="${extendSignCourse}">延长课时</a></li>
										<li><s:url id="changeSignCourse" action="changeSignCourse" namespace="/signcourse">
												<s:param name="signCourseId" value="id"></s:param>
											</s:url> <a href="${changeSignCourse}">转课/退费</a></li>
										<li><s:url id="modifySignCourse" action="modifySignCourse" namespace="/signcourse">
												<s:param name="id" value="id"></s:param>
											</s:url> <a href="${modifySignCourse}">修改选课情况</a></li>
									</ul>
								</div></td>
							<td class="${cssClass}"><s:date name="signTime" format="yyyy-MM-dd" /></td>
							<td class="${cssClass}">${signCourse.lessonCard} <s:if test="cardId != null && cardId.length > 0">
									<div>卡号:${signCourse.cardId}</div>
								</s:if>
							</td>
							<td class="${cssClass}">${signCourse.term} <s:if test="times != 0">
									,<s:property value="times" />次
							</s:if>
							</td>
							<td class="${cssClass}">
								<div>
									<s:date name="beginTime" format="yyyy/MM/dd" />
								</div>
								<div>
									-
									<s:date name="endTime" format="yyyy/MM/dd" />
								</div>
							</td>
							<td class="${cssClass}"><s:if test='!learnStatus.toString().equals("在读")'>
									<a class="confirm" href="${resumeCourse}" title="恢复课程">
										<i class="icon-play"></i>
									</a>
								</s:if> <s:else>
									<a class="frame" href="${createFreezeLog}" title="冻结课程">
										<i class="icon-pause"></i>
									</a>
								</s:else> <s:if test='!learnStatus.toString().equals("结课")'>
									<a class="confirm" href="${finishCourse}" title="结课">
										<i class="icon-stop"></i>
									</a>
								</s:if></td>
						</tr>
					</s:iterator>
				</s:else>
			</s:iterator>
		</table>
		<jsp:include page="/components/pagination/paginations.jsp"></jsp:include>
	</tiles:putAttribute>
</tiles:insertDefinition>